<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'firms-form',	
	'enableAjaxValidation'=>false,	
	'htmlOptions'=>array('enctype'=>'multipart/form-data'),
)); ?>

	<p class="note">Поля, отмеченные <span class="required">*</span> обязательны для заполнения</p>

	<?php echo $form->errorSummary($model); ?>

	<div class="row">
		<?php echo $form->labelEx($model,'title'); ?>
		<?php echo $form->textField($model,'title',array('size'=>60,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'title'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'id_section'); ?>
		<?php echo $form->dropDownList($model,'id_section',				
				CHtml::listData(Sections::model()->findAll(array('order'=>'order_id ASC')), 'id', 'name')); ?>
		<?php echo $form->error($model,'id_section'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'post'); ?>
		<?php $this->widget('application.extensions.cleditor.ECLEditor', array(
				'model'=>$model,
				'attribute'=>'post',
				'options'=>array(
					'width'=>800,
					'height'=>500,
					'useCSS'=>true,
				),
				'value'=>$model->post,
			));
		?>
		<?php echo $form->error($model,'post'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'url_phone'); ?>
		<?php echo $form->textField($model,'url_phone',array('size'=>60,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'url_phone'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'url_map'); ?>
		<?php echo $form->textField($model,'url_map',array('size'=>60,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'url_map'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'order_id'); ?>
		<?php echo $form->textField($model,'order_id'); ?>
		<?php echo $form->error($model,'order_id'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'enabled'); ?>
		<?php echo $form->checkBox($model,'enabled'); ?>
		<?php echo $form->error($model,'enabled'); ?>
	</div>

	<br />
	<hr />
	<a name="attaches"></a>
	<p><b>Загруженные изображения</b></p>
	<!-- uploads -->
	<div class="row">

		<?php if ( $model->id_icon == 0 ):?>
			<div style="color: red;"><b>иконка не установлена</b></div>
		<?php endif;?>
		<br />
		<?php echo CHtml::hiddenField('id_delete_attach', '', array('id'=>'id_delete_attach')); ?>
		<?php echo CHtml::hiddenField('id_icon_attach', '', array('id'=>'id_icon_attach')); ?>

		<table class="uploads" cellpadding="0" cellspacing="0">
		<?php foreach ($model->uploads as $attach): ?>
			<tr>
				<td width="110px" align="center"><img src="<?php echo 'uploads/'.$attach->file_name; ?>" <?php echo $attach->height > $attach->width ? 'height="110px"' : 'width="110px"'; ?>/></td>

				<td width="530px">
					<table class="uploads-info" width="95%" align="center" cellpadding="0" cellspacing="0">
					<tr><td>Загружен:</td><td>
						<b><?php echo date('Y-m-d H:m:s', $attach->upload_date); ?></b>
					</td></tr><tr><td>Название:</td><td>
						<b><?php echo $attach->original_name; ?></b>					
					</td></tr><tr><td>Размеры:</td><td>
						<b><?php echo $attach->width; ?> x <?php echo $attach->height; ?></b>
					</td></tr><tr><td>Объем:</td><td>
						<b><?php echo $attach->filesize; ?></b> байт
					</td></tr><tr><td>Ссылка:</td><td>
						<input class="attach" type="text" size="70" readonly value="<?php echo Yii::app()->request->getBaseUrl(true) . '/uploads/'.$attach->file_name; ?>" />
					</td></tr><tr><td>Описание:</td><td>
						<input class="attach" type="text" size="70" name="alt[<?php echo $attach->id; ?>]" value="<?php echo $attach->alt; ?>" />
					</td></tr>
					</table>
				</td>
				<td>					
					<?php echo CHtml::submitButton('Удалить', array('name'=>'delete_attach', 'onclick'=>'document.getElementById("id_delete_attach").value = '.$attach->id)); ?>
					<?php if ($attach->id != $model->id_icon):?>
						<?php echo CHtml::submitButton('Установить иконкой', array('name'=>'set_icon', 'onclick'=>'document.getElementById("id_icon_attach").value = '.$attach->id)); ?>
					<?php endif;?>
				</td>
			</tr>
		<?php endforeach; ?>
		</table>
	</div>
	<div class="row">
		<?php if ( !empty($errors) ): ?>
			<p>Errors on upload files</p>
			<?php echo implode(', ', $errors) . '<br />';?>
		<?php endif;?>

		<p><b>Загрузить новые файлы</b></p>
		<?php for ($index = 0; $index < 5; $index++): ?>
			<?php echo CHtml::fileField('upload['.$index.']', '', array('size'=>60, 'class'=>'attach')); ?><br />
		<?php endfor;?>
	</div>

	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Добавить' : 'Сохранить', array('name'=>'save')); ?>
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Добавить и выйти' : 'Сохранить и выйти', array('name'=>'save_exit')); ?>
	</div>


<?php $this->endWidget(); ?>
<br />
<br />


</div><!-- form -->